import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gio

# 加载资源文件
resource = Gio.Resource.load("loadres.gresource")
Gio.resources_register(resource)

class MyApp(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.builder = None
    def do_activate(self):
        if self.builder is None:
            # builder = Gtk.Builder()
            # builder.add_from_resource("/com/example/app/loadres.ui")
            self.builder = Gtk.Builder.new_from_resource("/com/example/app/loadres.ui")
            self.window = self.builder.get_object("main_window")
            self.window.set_application(self)
        self.window.present()

if __name__ == "__main__":
    app = MyApp(application_id="com.example.MyApp")
    app.run(None)